//============================================================================
// Name        : Training_data_conversor.cpp
// Author      : Italo Alfaro
// Version     :
// Copyright   :
// Description :
//============================================================================

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>


using namespace std;

int main () {
  string entrada;
  string salida;
  ifstream myfile ("pruebas_tomogramas.data");

  ofstream archivo ("result_pruebas.data");


  string entr []={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
  string sal []={"-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1"};
  //entr[0]="0";

  for(int g=0;g<18;g++){
      	cout << entr[g] << endl;
      	cout << sal[g] << endl;
  }

  if (myfile.is_open())
  {
	getline (myfile,entrada);
	archivo << entrada<<endl;
	while (!myfile.eof())
    {
	  string entr []={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
	  string sal []={"-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1","-1"};
      getline (myfile,entrada);
      string buf1;
      stringstream ss(entrada);
      vector<string> tokens;

      getline (myfile,salida);
      string buf2;
      stringstream ss_salida(salida);
      vector<string> tokens_salida;


      while (ss >> buf1){
    	  tokens.push_back(buf1);
      }

      while (ss_salida >> buf2){
    	  tokens_salida.push_back(buf2);
      }

      for(int i=0;i<18;i++){
    	  cout << tokens[i] << endl;
      }

      for(int i=0;i<18;i++){
    	  cout << tokens_salida[i] << endl;
      }
      cout << entrada << endl;
      cout << salida << endl;

      for(int i=1;i<19;i++){
    	  for(int j=i;j>0;j--){
    		  entr[18-j]=tokens[i-j];
    		  sal[18-j]=tokens_salida[i-j];
    	  }
    	  for(int g=0;g<18;g++){
    	    cout << entr[g] << endl;
    	  }
    	  for(int h=0;h<18;h++){
    	    cout << sal[h] << endl;
    	  }
    	  archivo << entr[0]<<" "<<entr[1]<<" "<<entr[2]<<" "<<entr[3]<<" "<<entr[4]<<" "<<entr[5]<<" "<<entr[6]<<" "<<entr[7]<<" "<<entr[8]<<" "<<entr[9]<<" "<<entr[10]<<" "<<entr[11]<<" "<<entr[12]<<" "<<entr[13]<<" "<<entr[14]<<" "<<entr[15]<<" "<<entr[16]<<" "<<entr[17]<<endl;
    	  archivo << sal[0]<<" "<<sal[1]<<" "<<sal[2]<<" "<<sal[3]<<" "<<sal[4]<<" "<<sal[5]<<" "<<sal[6]<<" "<<sal[7]<<" "<<sal[8]<<" "<<sal[9]<<" "<<sal[10]<<" "<<sal[11]<<" "<<sal[12]<<" "<<sal[13]<<" "<<sal[14]<<" "<<sal[15]<<" "<<sal[16]<<" "<<sal[17]<<endl;
    	  cout << endl;
      }
    }

  }else{
	  cout << "Unable to open file";
  }
  archivo.close();
  myfile.close();
  return 0;
}
